<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>修改密码</title>
<script type="text/javascript" src="javascript/window/openwindow.js"></script>
<script type="text/javascript">
    function submit() {
        var password = document.getElementById("password").value;
    	var oldPassword = document.getElementById("oldPassword").value;
    	var passwordConfirm = document.getElementById("passwordConfirm").value;
    	if (!oldPassword || oldPassword=="") {
            mmy_alert("请输当前密码！");
            return false;
        }
    	if (!password || password=="") {
    		mmy_alert("请输入新密码！");
            return false;
    	}
    	if (password != passwordConfirm) {
    		mmy_alert("请重新确认密码！");
    		return false;
    	}
    	//构造数据
        var data = "password=" + password;
        data += "&id=${user.id}";
        data += "&oldPassword=" + oldPassword;
        //创建xhr对象 
        var xhr = new XMLHttpRequest();
        //设置xhr请求的超时时间
        xhr.timeout = 3000;
        //设置响应返回的数据格式
        xhr.responseType = "text";
        //创建一个 post 请求，采用异步
        xhr.open('POST', 'UserServlet?action=updatePassword', true);
        //注册相关事件回调处理函数
        xhr.onload = function(e) { 
          if(this.status == 200||this.status == 304){
        	  mmy_alert(this.responseText);
          }
        };
        xhr.ontimeout = function(e) {  };
        xhr.onerror = function(e) {  };
        xhr.upload.onprogress = function(e) {  };
        //发送数据
        xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        xhr.setRequestHeader("cache-control", "no-cache");
        xhr.send(data);
    }
</script>
</head>
<body>
  <div>初始密码：<input id="oldPassword" type="password"></div>
  <div>新密码：<input id="password" type="password"></div>
  <div>确认密码：<input id="passwordConfirm" type="password"></div>
  <div>
    <button onclick="submit();">确认</button>
    &nbsp;&nbsp;
    <button onclick="javascript:history.go(-1);">返回</button></div>
</body>
</html>